package online.inote.common.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

/**
 * <p>
 * Desc: 
 * </p>
 *
 * @author XQF SUI
 * @created 2018年9月4日 下午10:19:45
 * @version 1.0
 */
public class ResultFactory extends BaseResultFactory {

	public static Map<String, Object> createResultMap(ResultEnum resultEnum, BindingResult result) {
		return createResultMap(resultEnum, getValidFailMsg(result));
	}
	
	public static String getValidFailMsg(BindingResult result) {

		List<String> msgList = new ArrayList<>();
		
		for (ObjectError error : result.getAllErrors()) {
			msgList.add(error.getDefaultMessage());
		}
		
		return StringUtils.join(msgList, ",");
	}
}